import Vue from 'vue'
import App from './App.vue'
import iView from 'iview'
import router from './router'
import Util from './libs/util';
import Bus from '@/components/bus/Bus.vue';
import '@/assets/style/common.less';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import 'iview/dist/styles/iview.css';
import '@/assets/style/common/customize.less';
import '@style/common/font.css';
import Http from './libs/http';
import LoginInfo from './libs/loginInfo';

Vue.use(ElementUI);
Vue.use(iView);
Vue.use(Bus);
Vue.use(Http);
Vue.use(LoginInfo);

window.Bus = Bus;
window.Util = Util;

Vue.config.productionTip = false;

window.DMap = {
    resizeEnable: true,
    zoom: 14,
    center: [106.542245, 29.561682],
    key: '5fbfab5b6f6d13a9bff742af384c7615',
    addressKey: '956fa8426889423864f4840af45f1b25'
};

// 入口路由拦截
router.beforeEach(({ meta, path }, from, next) => {
    Util.title(meta.title);
    let auth;
    if (meta.routeAuth === false) {
        auth = false;
    } else {
        auth = true;
    }
    //获取用户是否登陆;
    let user = window.sessionStorage.getItem('loginInfo');
    if (auth && !user && path !== '/login') {
        next({ path: '/login' });
    } else if (path === '/login' && user) {
        next({ path: '/' });
    }
    next();
});

new Vue({
    router,
    render: h => h(App)
}).$mount('#app');
